import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useCalculationStore = defineStore('calculation', () => {
  // 计算状态
  const isCalculating = ref(false)
  const calculationCompleted = ref(false)
  const currentCalculationType = ref('') // 当前计算类型：pose-feasibility, target-optimization, tolerance-design

  // 开始计算
  const startCalculation = (type) => {
    isCalculating.value = true
    calculationCompleted.value = false
    currentCalculationType.value = type
  }

  // 完成计算
  const completeCalculation = () => {
    isCalculating.value = false
    calculationCompleted.value = true
  }

  // 重置计算状态
  const resetCalculation = () => {
    isCalculating.value = false
    calculationCompleted.value = false
    currentCalculationType.value = ''
  }

  // 检查是否可以下载
  const canDownload = () => {
    return calculationCompleted.value && !isCalculating.value
  }

  return {
    // 状态
    isCalculating,
    calculationCompleted,
    currentCalculationType,

    // 方法
    startCalculation,
    completeCalculation,
    resetCalculation,
    canDownload
  }
})

